package org.easy.db.generator;

import lombok.Data;
import lombok.ToString;
import org.easy.db.Type;
import org.easy.db.generator.util.StrUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description: 总体的配置类
 * @Author: wxl
 * @CreateTime: 2023/1/18 14:56
 */
@Data
@ToString
public class GlobalConfigBuilder {

    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    private Type type;

    private String moduleName;

    /**
     * 表名
     */
    private String tableName;

    /**
     * 是否开启swagger 默认开启
     */
    private boolean isUserSwagger;
    /**
     * 作者
     */
    private String author;

    /**
     * 文件指定输出位置 使用了默认的地址
     */
    private String outPutDir;
    /**
     * 父包名
     */
    private String parentPackage;

    /**
     * 日期
     */
    private String date;

    /**
     * 模块名
     */
    private TableDefinition table;

    /**
     * 模板路径
     */
    private Map<String,String> templateMap;

    public GlobalConfigBuilder (String tableName,String moduleName,String parentPackage,String author,boolean isUserSwagger) {
        this(tableName, moduleName,parentPackage,author);
        this.isUserSwagger = isUserSwagger;
    }

    public GlobalConfigBuilder (String tableName,String moduleName,String parentPackage,String author) {
        this(tableName, moduleName,parentPackage);
        if (null == author) {
            author = "Lanna";
        }
        this.author = author;
    }

    public GlobalConfigBuilder (String tableName,String moduleName,String parentPackage) {
        this.tableName = tableName;
        this.isUserSwagger = true;
        this.templateMap = new ConcurrentHashMap<>();
        this.moduleName = moduleName;
        this.table = new TableDefinition(tableName,this.moduleName,parentPackage,templateMap);
        this.parentPackage = parentPackage;
        this.date = LocalDateTime.now().format(DATE_TIME_FORMATTER);
        this.outPutDir = StrUtils.getPackageOriginPath();
    }

}
